package model;

import graphquerying.reachability.GRILIndexManager;
import graphquerying.reachability.RGraph;

import java.util.ArrayList;

public class QueryManager {

	/**
	 * 
	 * @return all matched subgraphs
	 */
	public ArrayList<Graph> subgraphQuery(Graph dataGraph, QueryGraph queryGraph) {
		// TODO
		return null;
	}

	/**
	 * 
	 * is ther a path between two nodes?
	 */
	public boolean reachabilityQuery(Graph dataGraph, String sourceNodeId,
			String targetNodeId) {
		RGraph rGraph = RGraph.readCache(String.valueOf(dataGraph.hashCode()));
		if (rGraph == null) {
			rGraph = new RGraph(dataGraph);
		}
		GRILIndexManager.constructIndex(rGraph);
		boolean result = true;
		if (!rGraph.getIdMap().containsKey(sourceNodeId)) {
			System.out.println("Node id: " + sourceNodeId + " is not in the graph");
			result = false;
		} 
		if (!rGraph.getIdMap().containsKey(targetNodeId)) {
			System.out.println("Node id: " + targetNodeId + " is not in the graph");
			result = false;
		}
		if (result) {
			long startTime = System.nanoTime();
			result = GRILIndexManager.isReachable(rGraph, sourceNodeId, targetNodeId);
			System.out.println("Reachability query time: " + (System.nanoTime() - startTime) / 1000000.0 + "ms");
		}
		return result;
	}

	/**
	 * @return
	 */
	public Path getShortestPathBetweenTwoNodes(Graph dataGraph,
			String sourceNodeId, String targetNodeId) {
		// TODO
		return null;
	}

	/**
	 * 
	 * @return one path between two nodes
	 */
	public Path getOneSimplePathBetweenTwoNodes(Graph dataGraph,
			String sourceNodeId, String targetNodeId) {
		// TODO
		return null;
	}

	/**
	 * 
	 * @return Top K simple paths between two nodes.
	 */
	public ArrayList<Path> getTopKSimplePathsBetweenTwoNodes(Graph dataGraph,
			String sourceNodeId, String targetNodeId) {
		// TODO
		return null;
	}

}
